package org.hong.samples.service.imp;

import java.util.List;

import org.hong.samples.dao.UserHibernateDAO;
import org.hong.samples.dao.UserSubjectDao;
import org.hong.samples.model.ExamSubject;
import org.hong.samples.model.ExamTest;
import org.hong.samples.model.ExamTestType;
import org.hong.samples.model.VO.ExamSubjectVO;
import org.hong.samples.model.VO.ExamTestTypeVO;
import org.hong.samples.model.VO.ExamTestVO;
import org.hong.samples.service.UserHibernateService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserHibernateServiceImp implements UserHibernateService{
	
	@Autowired
	private UserHibernateDAO userHibernateDAO;
	@Autowired
	private UserSubjectDao userSubjectDAO;

	@Override
	public List<ExamTest> findAllUsers() {
		return userHibernateDAO.findAllUsers();
	}

	@SuppressWarnings("unused")
	@Override
	public ExamTestVO getUserById(Integer id) {
		ExamTest examTest = userHibernateDAO.getUserById(id);
		ExamSubject examSubject = userSubjectDAO.getSubjectById(examTest.getExamSubject().getSubId());
		
		if(examTest != null){
			ExamTestVO examTestVO = new ExamTestVO();
			BeanUtils.copyProperties(examTest, examTestVO);
			ExamSubjectVO examSubjectVO = new ExamSubjectVO();
			BeanUtils.copyProperties(examSubject, examSubjectVO);
			ExamTestTypeVO examTestTypeVO = new ExamTestTypeVO();
			BeanUtils.copyProperties(examTest.getExamTestType(), examTestTypeVO);
			examTestVO.setExamSubjectVO(examSubjectVO);
			examTestVO.setExamTestTypeVO(examTestTypeVO);
			return examTestVO;
		}
		return null;
	}

	@Override
	public void editUser(ExamTest user) throws Exception {
		userHibernateDAO.editUser(user);
	}

	@Override
	public void saveUser(ExamTest user) throws Exception {
		userHibernateDAO.saveUser(user);
	}

	@Override
	public void deleteUser(Integer id) throws Exception {
		userHibernateDAO.deleteUser(id);
		
	}

	@Override
	public List<ExamSubject> finAllSubject() {
		// TODO Auto-generated method stub
		return userHibernateDAO.finAllSubject();
	}

	@Override
	public List<ExamTestType> finAllType() {
		// TODO Auto-generated method stub
		return userHibernateDAO.finAllType();
	}

	@Override
	public List<ExamTest> getTestListBySubAndTestType(Integer subId, Integer integer) {
		// TODO Auto-generated method stub
		return userHibernateDAO.getTestListBySubAndTestType(subId, integer);
	}

	@Override
	public List<ExamTest> getTestListByIdList(List<Integer> randomTestIdList) {
		// TODO Auto-generated method stub
		return userHibernateDAO.getTestListByIdList(randomTestIdList);
	}

	@Override
	public List<ExamTest> getTestBySubjectId(String subId) {
		// TODO Auto-generated method stub
		return userHibernateDAO.getTestBySubjectId(subId);
	}

}
